<?php
// 提示消息淡出效果
Yii::app()->clientScript->registerScript(
   'myHideEffect',
   '$(".info").animate({opacity: 0.7}, 5000).fadeOut("slow");',
   CClientScript::POS_READY
);
?>
<?php
$this->breadcrumbs=array(
	$type=>array('index', 'tid'=>$model->tid),
	$model->title,
);
if($model->status !=0){
    $this->menu=array(
	
	array('label'=>'创建事件', 'url'=>array('create','tid'=>DefineBox::EVENT_TYPE_CODE)),
	array('label'=>'创建知识', 'url'=>array('create','tid'=>DefineBox::PEDIA_TYPE_CODE)),
	array('label'=>'创建地点', 'url'=>array('create', 'tid'=>DefineBox::SCENE_TYPE_CODE)),
	array('label'=>'创建角色', 'url'=>array('create', 'tid'=>DefineBox::ROLE_TYPE_CODE)),
	array('label'=>'创建物品', 'url'=>array('create', 'tid'=>DefineBox::OBJECT_TYPE_CODE)),
    );
}
// 调用分类并显示
$this->category = HandleBox::getCategory();
?>

<?php 
if(isset(Yii::app()->user->id)){
	if ($poll){
		if ($this->hasPoll != false){
			$vote = PollVote::model()->findByAttributes(array('uid'=>Yii::app()->user->id, 'pid'=>$poll->id));
			if ($vote){
				echo "<div style = 'color: #000; background:#fff4d4; padding: 5px; margin: 0 0 10px 0; height: 50px; border-left: 10px #666 solid; '>";
				echo "当前本内容正在申请一个投票， 将于".date('Y-m-d H:i:s',$poll->finish_time)."结束。<br />";
				echo "您已经投过票了，".CHtml::link('点击这里', array('/community/viewpoll', 'id'=>$poll->id, 'tid'=>$poll->tid))."查看投票情况。";
				echo "</div>";
				$this->hasPoll = false;
			}
		}
	}
	if($this->hasPoll == true){
		echo "<div style = 'background: #ffebcc; padding: 10px; border: 2px #f8e1d6 solid;'>";
		echo "该内容正在申请提升成熟度，申请理由如下：<br />";
		echo $poll->description;
	?>
	
	<div class="form">
	<?php $form=$this->beginWidget('CActiveForm', array(
		'id'=>'node-poll-form',
		'enableAjaxValidation'=>false,
	)); ?>
	
		<?php echo $form->errorSummary($modelVote); ?>
		
		<div class="row">
			<?php echo $form->radioButtonList($modelVote,'value', array(1=>'赞成', 0=>'反对'),
				array('separator'=>'', 'labelOptions'=>array('class'=>'labelForRadio'))
			); ?>
			<?php echo $form->error($modelVote,'value'); ?>
		</div>
	
		<div class="row">
			<?php echo $form->labelEx($modelVote,'reason'); ?>
			<?php echo $form->textArea($modelVote,'reason',array('rows'=>2,'cols'=>74)); ?>
			<?php echo $form->error($modelVote,'reason'); ?>
		</div>
		
		<div class="row buttons">
			<?php echo CHtml::submitButton($modelVote->isNewRecord ? '投票' : '更新'); ?>
		</div>
	
	<?php $this->endWidget(); ?>
	
	</div><!-- form -->
	<?php 
	echo "</div>";
	}
}
?>

<div style = "float: right">
	<?php
		 if($model->status == DefineBox::NODE_STATUS_NORMAL){
		 	if ($model->access != DefineBox::NODE_ACCESS_PROTECED){
		 		echo CHtml::link('编辑', array('update', 'id'=>$model->id))." | ";
		 	}
		 	elseif($model->access == DefineBox::NODE_ACCESS_PRIVATE) {
		 		echo "<span  id = 'demo-tip-yellowsimple' title='私有内容， 不允许编辑' class = 'fontGray'>编辑</span> | ";
		 	}
		 	else{
		 		if (HandleBox::isUserHelper($model->uid) == true or $model->uid = Yii::app()->user->id){
		 			echo CHtml::link('编辑', array('update', 'id'=>$model->id))." | ";
		 		}
		 		else{
		 			echo "<span  id = 'demo-tip-yellowsimple' title='内容受作者保护，需合作者方可编辑' class = 'fontGray'>编辑</span> | ";
		 		}
		 	}
	    }
	    elseif ($model->status == DefineBox::NODE_STATUS_EMPTY){
	    	echo CHtml::link('编辑', array('update', 'id'=>$model->id))." | ";
	    }
		echo CHtml::link('讨论', array('/nodetalk', 'id'=>$model->id))." | ";
		echo CHtml::link('历史版本', array('/noderevision', 'id'=>$model->id))." | ";
		echo chtml::link('查看作者', array('userlist', 'id'=>$model->id));
	?>
</div>

<h1><?php echo $model->title; ?></h1>

<?php 
switch ($model->access){
	case DefineBox::NODE_ACCESS_PROTECED:
		if (HandleBox::isUserHelper($model->uid) == true){
			echo "<div class = 'alart'>本页面受到创建作者的保护，你是该作者的合作者，可以进行编辑。</div>";
		}
		elseif($model->uid = Yii::app()->user->id){
			echo "<div class = 'alart'>你是该页面的创建者，该页面当前处于受保护状态，只有你及你的合作者可以编辑。</div>";
		}
		else{
			echo "<div class = 'alart'>本页面受到创建作者的保护，如想参与编辑，请<a href = '#'>申请成为该作者的合作者</a></div>";
		}
		break;
	case DefineBox::NODE_ACCESS_PRIVATE:
		echo "<div class = 'alart'>本页面属创建作者私有，不允许进行编辑。</div>";
		break;
}
?>

<div style = "position: relative; top: -15px; right: 0; background: #EEE; margin-bottom: 20px;">
<?php 
	// 获取内容操作提示信息
	if(Yii::app()->user->hasFlash('nodeHandleInfo')){
		echo '<div class = "info">';
			echo "<div class = 'infoImg'></div>";
			echo "<div class = 'infoText'>";
			echo Yii::app()->user->getFlash('nodeHandleInfo');
			echo "</div>";
		echo '</div>';
	}
?>
</div>
<div> 
<!--
<span class = "status bgRed" ><?php echo $model->statusText; ?></span>
<span class = "status bgRed"><?php echo $model->accessText; ?></span>
-->
<span class = "status bgBlue tip" title="我们访问的次数"><?php echo $model->visit; ?>次访问</span>
<span class = "status bgYellow"><?php echo CHtml::link($cite, array('cite', 'sid'=>$model->id)); ?>个引用</span>
<?php
if (!$poll){
	echo "<span class = 'status bgGreen'>";
	echo $model->level; 
	echo "成熟度";
	echo CHtml::link('+', array('/community/polllevel', 'nid'=>$model->id, 'tid'=>DefineBox::POLL_LEVEL_CODE));
	echo "</span>";
}
?>
</div>

<div class = "bodyBox">

<?php 
	$event = '';
	$scene = '';
	$role = '';
	$object = '';
	$pedia = '';
	foreach ($nodeMapping as $key=>$node){
		switch ($node->snode->tid){
			case DefineBox::EVENT_TYPE_CODE:
				if ($node->snode->status == DefineBox::NODE_STATUS_EMPTY){
					$event .= CHtml::link($node->snode->title, array('view', 'id'=>$node->snode->id), array('class'=>'red')).' | ';
				}
				else{
					$event .= CHtml::link($node->snode->title, array('view', 'id'=>$node->snode->id)).' | ';
				}
				break;
			case DefineBox::SCENE_TYPE_CODE:
				if ($node->snode->status == DefineBox::NODE_STATUS_EMPTY){
					$scene .= CHtml::link($node->snode->title, array('view', 'id'=>$node->snode->id), array('class'=>'red')).' | ';
				}
				else{
					$scene .= CHtml::link($node->snode->title, array('view', 'id'=>$node->snode->id)).' | ';
				}
				break;
			case DefineBox::ROLE_TYPE_CODE:
				if ($node->snode->status == DefineBox::NODE_STATUS_EMPTY){
					$role .= CHtml::link($node->snode->title, array('view', 'id'=>$node->snode->id), array('class'=>'red')).' | ';
				}
				else{
					$role .= CHtml::link($node->snode->title, array('view', 'id'=>$node->snode->id)).' | ';
				}
				break;
			case DefineBox::OBJECT_TYPE_CODE:
				if ($node->snode->status == DefineBox::NODE_STATUS_EMPTY){
					$object .= CHtml::link($node->snode->title, array('view', 'id'=>$node->snode->id), array('class'=>'red')).' | ';
				}
				else{
					$object .= CHtml::link($node->snode->title, array('view', 'id'=>$node->snode->id)).' | ';
				}
				break;
			case DefineBox::PEDIA_TYPE_CODE:
				if ($node->snode->status == DefineBox::NODE_STATUS_EMPTY){
					$pedia .= CHtml::link($node->snode->title, array('view', 'id'=>$node->snode->id), array('class'=>'red')).' | ';
				}
				else{
					$pedia .= CHtml::link($node->snode->title, array('view', 'id'=>$node->snode->id)).' | ';
				}
				break;
		}
	}
	if ($event){
		echo '<div class = "nodeMapping">事件：'.substr($event, 0, -2).'</div>';
	}
	if ($scene){
		echo '<div class = "nodeMapping">地点：'.substr($scene, 0, -2).'</div>';
	}
	if ($role){
		echo '<div class = "nodeMapping">角色：'.substr($role, 0, -2).'</div>';
	}
	if ($object){
		echo '<div class = "nodeMapping">物品：'.substr($object, 0, -2).'</div>';
	}
	if ($pedia){
		echo '<div class = "nodeMapping">知识：'.substr($pedia, 0, -2).'</div>';
	}
?>
	<div class = "bodyMain">
	<?php 
		if ($model->body != null){
			echo $model->body; 
		}else{
			echo "尚无内容，有待你来".CHtml::link('撰写', array('/node/update', 'id'=>$model->id))."。";
		}
	?>
	</div>
</div>
<div style = "padding: 5px 10px; background: #F2F2F2; color: #AAA;">
<?php 
if ($model->create_time != 0){
	echo "更新于".date("Y年m月d日H点i分", $model->update_time).'，';
	echo "创建于".date("Y年m月d日H点i分", $model->create_time); 
}
?>
</div>

<div style = "margin-top: 10px;">
<?php 
if ($tags){
	$tagString= '';
	foreach ($tags as $tag){
		$tagString .= '<span class = "tag">'.CHtml::link($tag->tag, array('/tag/view', 'tag'=>$tag->tag)).'</span>';
	}
	echo mb_substr($tagString, 0);
}
?>
</div>

<?php Yii::app()->clientScript->registerCoreScript('jquery');?>
<?php 
$cs=Yii::app()->clientScript;
$cs->registerScriptFile(Yii::app()->baseUrl . '/js/poshytip-1.1/jquery.poshytip.min.js', CClientScript::POS_HEAD);
$cs->registerCssFile(Yii::app()->baseUrl . '/js/poshytip-1.1/tip-yellowsimple/tip-yellowsimple.css');
$cs->registerCssFile(Yii::app()->baseUrl . '/js/poshytip-1.1/tip-yellow/tip-yellow.css');
?>

<script type="text/javascript">
<!--
$('.tip').poshytip({
	className: 'tip-yellowsimple',
	showTimeout: 1,
	alignTo: 'target',
	alignX: 'center',
	offsetY: 5,
	allowTipHover: false
});
//-->
</script>